'use strict';
module.exports = {
  showTopTips(content = '', options = {}) {
    let lmfTopTips = this.data.lmfTopTips || {};
    // 如果已经有一个计时器在了，就清理掉先
    if (lmfTopTips.timer) {
      clearTimeout(lmfTopTips.timer);
      lmfTopTips.timer = undefined;
    }

    if (typeof options === 'number') {
      options = {
        duration: options
      };
    }

    // options参数默认参数扩展
    options = Object.assign({
      duration: 3000
    }, options);

    // 设置定时器，定时关闭topTips
    let timer = setTimeout(() => {
      this.setData({
        'lmfTopTips.show': false,
        'lmfTopTips.timer': undefined
      });
    }, options.duration);

    // 展示出topTips
    this.setData({
      lmfTopTips: {
        show: true,
        content,
        options,
        timer
      }
    });
  }
};